const Controller = require("egg").Controller;

class ThingsController extends Controller {
  async info() {
    const { ctx, app } = this;
    const { tid } = ctx.params;
    const { title, summary, content } = await app.mysql.get("things", { tid });
    let imgs = [];
    await new Promise((resolve) => {
      resolve(app.mysql.select("imgs", { where: { tid } }));
    }).then((r) => r.forEach((img) => imgs.push(img.imgurl)));
    console.log(imgs);
    ctx.body = JSON.stringify({ title, summary, content, imgs });
  }
}

module.exports = ThingsController;
